/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：SettingScreen.java <br>
 * 创建时间：2014-1-11 下午5:20:21 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;

import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.GameConstants;
import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.MainCharTile;
import lostland.gmud.exv2.MapScreen;
import lostland.gmud.exv2.MapTile;
import lostland.gmud.exv2.SavingScreen;
import lostland.gmud.exv2.blgframework.impl.BLGGraphics;
import lostland.gmud.exv2.ui.core.MenuScreen;
import lostland.gmud.exv2.ui.core.NewButton;

/**
 * 类名：SettingScreen <br>
 * 说明：
 *
 * @author 12548
 */
public class SettingScreen extends MenuScreen {


	static SettingBorder nborder;

	static final String s[][] = new String[][]{
			{"键位：传统键位", "键位：标准键位"},
			{"显示菜单键：否", "显示菜单键：是"},
			{"对话语音：关闭", "对话语音：开启"},
			{"返回键退出：否", "返回键退出：是"},
			{"地图图块：传统单色版", "地图图块：标准上色版", "地图图块：卡通美化版"},
			{"武功学习不间断：否", "武功学习不间断：是"},
			{"按键颜色：水晶绿色", "按键颜色：水晶红色", "按键颜色：酷黑火焰", "按键颜色：酷黑绿影", "按键颜色：水晶透明"},
			{"地图分辨率：标准", "地图分辨率：大", "地图分辨率：特大"},
			{"自动检查更新：否", "自动检查更新：是"},
			{"只在WIFI下检查更新：否", "只在WIFI下检查更新：是"},
			{"音乐：关闭", "音乐音量：低", "音乐音量：中", "音乐音量：高"},
			{"自动添加轻功点：关闭", "自动添加轻功点：开启"},
			{"菜单键使用轻功：关闭", "菜单键使用轻功：开启"}
	};

	static int pointer[];

	/**
	 * @param instance
	 * @param buttons
	 */
	public SettingScreen() {
		super(getButtons());
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.MenuScreen#onClick(int)
	 */
	@Override
	protected void onClick(int index) {
		pointer[index]++;
		if (pointer[index] >= s[index].length) {
			pointer[index] = 0;
		}

		Game.classickeymap = Gmud.int2bool(pointer[0]);
		NewButton.menubutton = Gmud.int2bool(pointer[1]);
		Game.soundEnabled = Gmud.int2bool(pointer[2]);
		Game.backkeyquit = Gmud.int2bool(pointer[3]);
		Gmud.tileset = pointer[4];
		Game.uninterruptible = Gmud.int2bool(pointer[5]);
		NewButton.color = pointer[6];
		Game.resolution_level = pointer[7];
		Game.autocheckupdate = Gmud.int2bool(pointer[8]);
		Game.updateonlyonwifi = Gmud.int2bool(pointer[9]);
		Game.bgm_level = pointer[10];
		Game.autoAddFlyPoint = Gmud.int2bool(pointer[11]);
		Game.menuKeyForFly = Gmud.int2bool(pointer[12]);

		if (Game.bgm_level == 0) {
			getGame().stopBGM();
		} else {
			getGame().playBGM();
		}

		getGame().refreshBGMVolume();

		if (index == 4) {
			MapScreen.getInstance().initMap(MapScreen.getInstance().getMap());
		}

		if (index == 7) {
			MapScreen.C_ROWS = GameConstants.RES_W[Game.resolution_level];
			MapScreen.C_COLUMNS = GameConstants.RES_H[Game.resolution_level];

			getGame().mapFB = Bitmap.createBitmap(GameConstants.RES_W[Game.resolution_level] * MapTile.TILE_WIDTH,
					GameConstants.RES_H[Game.resolution_level] * MapTile.TILE_WIDTH, Config.ARGB_8888);

			((BLGGraphics) getGame().getGraphics()).mapCanvas = new Canvas(getGame().mapFB);

			MapScreen.getInstance().jumpTo(MapScreen.getInstance().getMap().id, MainCharTile.absX(), MainCharTile.absY(), MainCharTile.getInstance().currentDirection);
		}

		AutoButton ab = (AutoButton) buttons[index];
		ab.setS(s[index][pointer[index]]);

		SavingScreen.savePerf();
		refreshButtons();
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.MenuScreen#onCancel()
	 */
	@Override
	public void onCancel() {
		getGame().popScreen();
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.ButtonControlledScreen#show()
	 */
	@Override
	protected void show() {
		MapScreen.getInstance().getMap().draw(MapTile.getInstance(), MapScreen.X, MapScreen.Y);
		MainCharTile.getInstance().drawInMap(MainCharTile.getInstance().currentDirection,
				MainCharTile.getInstance().currentStep, MainCharTile.getInstance().X, MainCharTile.getInstance().Y);
		nborder.draw();

		for (int i = 0; i < buttons.length; i++) {
			buttons[i].draw();
		}
	}

	static AutoButton[] getButtons() {
		pointer = new int[s.length];
		pointer[0] = Gmud.bool2int(Game.classickeymap);
		pointer[1] = Gmud.bool2int(NewButton.menubutton);
		pointer[2] = Gmud.bool2int(Game.soundEnabled);
		pointer[3] = Gmud.bool2int(Game.backkeyquit);
		pointer[4] = Gmud.tileset;
		pointer[5] = Gmud.bool2int(Game.uninterruptible);
		pointer[6] = NewButton.color;
		pointer[7] = Game.resolution_level;
		pointer[8] = Gmud.bool2int(Game.autocheckupdate);
		pointer[9] = Gmud.bool2int(Game.updateonlyonwifi);
		pointer[10] = Game.bgm_level;
		pointer[11] = Gmud.bool2int(Game.autoAddFlyPoint);
		pointer[12] = Gmud.bool2int(Game.menuKeyForFly);

		nborder = new SettingBorder();

		AutoButton t[];
		t = new AutoButton[s.length];
		for (int i = 0; i < s.length; i++) {
			t[i] = new AutoButton(nborder.x + 1, nborder.y + 1 + i * 12, s[i][pointer[i]]);
		}

		return t;
	}


}
